<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3_AngularJS函数库3</title>
    <script src="../lib/angularjs.js"></script>
</head>

<body ng-app="myApp" ng-controller="myCtrl">

</body>
<script>
    const myApp = angular.module("myApp", [])
    myApp.controller("myCtrl", ["$scope", function ($scope) {
        // 19、angular.bind，该方法用于改变一个函数的this，然后返回一个新的函数（类似js中的bind）。
        let obj1 = {
            name: "AA",
        }
        let obj2 = {
            name: "BB",
            funcB: function (args1, args2, args3) {
                console.log("this：", this);
                console.log("args1：", args1);
                console.log("args2：", args2);
                console.log("args3：", args3);
            }
        }
        console.log("【angular.bind之前】");
        obj2.funcB("abc", "cde");
        console.log("【angular.bind之后】");
        let newFuncB = angular.bind(obj1, obj2.funcB, "123", "456")
        newFuncB("111")

        // 20、angular.merge，类似angular.extend，唯一区别是merge为深拷贝。
        let obj3 = {
            name: 'Shaun',
            age: 35,
            birthDate: new Date(1997, 5, 27),
            skills: {
                dotNet: {
                    level: 'expert',
                    years: 10
                },
                javaScript: {
                    level: 'newbie',
                    years: 2
                }
            },
            mvp: [
                2011,
                2012,
                2013,
                2014,
                2015
            ]
        };
        let obj4 = {
            name: 'Ziyan',
            age: 45,
            skills: {
                dotNet: {
                    level: 'hero',
                    years: 100,
                    active: true
                },
            },
            mvp: [
                2016
            ]
        };
        let mergedObj = angular.merge({}, obj3, obj4)
        console.log("angular.merge：", mergedObj);
    }])
</script>

</html>